package ua.com.noobs.numbers;

public class ProgressionUtils {
	
	public static double getSumGeometricProgression(double p, double q) {
		return p / (1 - q);
	}
	
	public static double getSumGeometricProgression(double b0, double q, double n) {
		if (q != 1)
			return (b0 * (Math.pow(q, n) - 1.0)) / (q - 1.0);
		else
			return n * b0;
	}
	
	public static double getGeometricProgressionElement(double b0, double q, long n) {
		return b0 * Math.pow(q, n - 1);
	}
	
	public static long getSumArifmeticProgression(long a0, long difference, long size) {
		return (2L * a0 + ((size - 1) * difference)) * size / 2L;
	}
	
	public static long getArifmeticProgressionElement(long a0, long difference, long n) {
		return a0 + (n - 1) * difference;
	}
}
